package com.ad.pet.common.data.injector.module;

import android.app.NotificationManager;
import android.content.Context;
import android.view.LayoutInflater;

import com.ad.pet.common.data.http.HttpHelp;
import com.ad.pet.common.data.utils.FileUtil;
import com.ad.pet.common.data.utils.JsonUtil;
import com.ad.pet.common.data.utils.SpUtil;
import com.ad.pet.common.data.utils.ui.ResourcesUtil;
import com.ad.pet.common.data.utils.ui.ToastUtil;
import com.ad.pet.common.data.utils.ui.UIUtil;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

/**
 * @author gzsll
 */
@Module
public class ApplicationModule {

    private final Context context;

    public ApplicationModule(Context context) {
        this.context = context;
    }

    @Provides
    @Singleton
    public Context provideApplicationContext() {
        return context.getApplicationContext();
    }

    @Provides
    @Singleton
    public ToastUtil provideToastUtil(Context context) {
        return new ToastUtil(context);
    }

    @Provides
    @Singleton
    public JsonUtil provideJsonUtil() {
        return new JsonUtil();
    }

    @Provides
    @Singleton
    public ResourcesUtil provideResourcesUtil(Context context) {
        return new ResourcesUtil(context);
    }

    @Provides
    @Singleton
    public UIUtil provideUIUtil(Context context) {
        return new UIUtil(context);
    }

    @Provides
    @Singleton
    public FileUtil provideFileUtil(Context context, ResourcesUtil resourcesUtil) {
        return new FileUtil(context, resourcesUtil);
    }

    @Provides
    @Singleton
    public SpUtil provideSpUtil(Context context) {
        return new SpUtil(context);
    }

    @Provides
    @Singleton
    OkHttpClient provideApiOkHttpClient(HttpHelp httpHelp) {
        return httpHelp.getOkHttpClient();
    }

    @Provides
    @Singleton
    Retrofit provideApiRetrofit(HttpHelp httpHelp, OkHttpClient okHttpClient, ResourcesUtil resourcesUtil) {
        return httpHelp.getRetrofit(okHttpClient, resourcesUtil);
    }


    @Provides
    @Singleton
    LayoutInflater provideLayoutInflater(Context context) {
        return (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Provides
    @Singleton
    NotificationManager provideNotificationManager(Context mContext) {
        return (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    }

    @Provides
    @Singleton
    HttpHelp provideOkHttpHelper() {
        return new HttpHelp(context);
    }

}
